package com.winteam.View;

import com.winteam.Bean.RoomInfo;
import com.winteam.Controler.Select;
import com.winteam.Controler.Updata;

import org.junit.Test;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.Vector;

public class BatchAddRoom extends JFrame {
	Updata ud=new Updata();
	
	private JTextField textField_1;



	public BatchAddRoom() {
		super.setTitle("添加房间信息");
		this.setBounds(0, 0, 500, 492);//设置大小
		this.setLocationRelativeTo(null);//让窗口在屏幕中间显示
 	    this.setResizable(true);//让窗口大小不可改变
		getContentPane().setLayout(null);
		getContentPane().setBackground(new Color(231,215,183));
		JLabel label = new JLabel("批量房间参数");
		label.setBounds(14, 13, 126, 18);
		getContentPane().add(label);
		
		JLabel label_1 = new JLabel("房间类型：");
		label_1.setBounds(125, 140, 90, 18);
		getContentPane().add(label_1);
		
		JLabel label_2 = new JLabel("房间号:");
		label_2.setBounds(125, 185, 90, 18);
		getContentPane().add(label_2);


		textField_1 = new JTextField();
		textField_1.setBounds(210, 185, 164, 24);
		getContentPane().add(textField_1);
		textField_1.setColumns(10);
		

		

		
		JComboBox comboBox = new JComboBox();
		Vector<String> roomlx =new Vector<String>();
		List<String> roomlx1 = new Select().getRoomlx();
		for (String s : roomlx1) {
			roomlx.add(s);
		}
		comboBox.setModel(new DefaultComboBoxModel(roomlx));
		comboBox.setBounds(210, 140, 104, 24);
		getContentPane().add(comboBox);
		JLabel state = new JLabel("房间状态:");
		state.setBounds(125, 220, 90, 18);
		getContentPane().add(state);
		//房间状态
		JRadioButton  yse = new JRadioButton("可用");
		yse.setBounds(210, 220, 70, 18);
		JRadioButton  not = new JRadioButton("不可用");
		not.setBounds(280, 220, 100, 18);
		ButtonGroup states= new ButtonGroup();
		states.add(yse);
		states.add(not);
		getContentPane().add(yse);
		getContentPane().add(not);
		JButton button = new JButton("保存");
		button.setIcon(new ImageIcon(this.getClass().getResource("img\\save.gif")));
		button.setBounds(91, 283, 113, 27);
		getContentPane().add(button);
		//保存按钮添加一个添加房间事件
		button.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
			String roomtype =(String) comboBox.getSelectedItem();
				int roomId = new Select().selectRoomId(roomtype);
 			int state=0;
				if (not.isSelected()){
					state = 2;
				}else if (yse.isSelected()){
					state = 1;
				}else {
					JOptionPane.showMessageDialog(null,"请设置状态!!");
					return;
				}
				if (textField_1.getText().equals("")){
					JOptionPane.showMessageDialog(null,"请设置房间号!!");
					return;
				}
				if (ud.addRomminf(roomId,state,textField_1.getText())) {
					JOptionPane.showMessageDialog(null,"添加成功");
					dispose();
				}
			}
		});
		
		JButton button_1 = new JButton("取消");
		button_1.setIcon(new ImageIcon(this.getClass().getResource("img\\cancel.gif")));
		button_1.setBounds(285, 283, 113, 27);
		getContentPane().add(button_1);
		button_1.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				dispose();
			}
		});
	}

	public static void main(String[] args) {
		new BatchAddRoom().setVisible(true);
	}

}
